<?php
$this->pageTitle = $model->name;
?>
<style>
</style>

<div style="width:270px;float:left;">
<div id="ProductSortCssID">

<ul id="pstMenu">

<?php 
$children = ProductCategory::model()->findAll(array('condition'=>'parent_id=1'));
foreach($children as $cat) {
    $list[] = $cat->id;
?>
<li>
    <?php echo CHtml::link($cat->name, array('productCategory/index','id'=>$cat->id));?>
    <ul>
        <?php 
        $subcat = ProductCategory::model()->findAll(array('condition'=>'parent_id='.$cat->id));
        foreach($subcat as $a) {
            echo "<li>".CHtml::link($a->name, array('productCategory/index','id'=>$a->id))."</li>";

        }
             ?>
    </ul>
</li>
<?php } ?>

</ul>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<script type="text/javascript">
sfHover = function() { 
    var sfEls = document.getElementById("pstMenu").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) { 
        sfEls[i].onmouseover=function() { 
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() { 
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

</script>
</div>
</div>
<div style="width:700px;float:right;margin:0px 0px 50px 0px;">
    <div id="bread">
    <a href="/"><?php echo Yii::t('t', 'Home')?></a>
    >>
<?php
$father = ProductCategory::model()->findByPk($model->parent_id); 
if($father) {
?>
    <a href="<?php echo Yii::app()->createUrl('productCategory/index', array('id'=>$model->parent_id));?>"><?php echo $father->name;?></a>
    >>
<?php } ?>
<?php echo $model->name;?>
    </div>
    <div id="main-content">
    <?php 
    $cnt = Product::model()->count(array('condition'=>'category_id='.$model->id));
    if($cnt > 0)  {
        $dataProvider=new CActiveDataProvider('Product', array(
            'criteria'=>array(
                'condition'=>'category_id='.$model->id,
                'order'=>'date DESC',
            ),
            'pagination'=>array(
                'pageSize'=>5,
            ),
        ));
    } else {

        if($model->id == 1) {
            $list = ProductCategory::model()->findAll(array('condition'=>'parent_id!=1'));
        } else {
            $list = ProductCategory::model()->findAll(array('condition'=>'parent_id='.$model->id));
        }


        $o = array(-1);
        foreach($list as $l) {
            $o[] = $l->id;
        }

        $dataProvider=new CActiveDataProvider('Product', array(
            'criteria'=>array(
                'condition'=>'category_id in (' . join(",", $o) . ')',
                'order'=>'date DESC',
            ),
            'pagination'=>array(
                'pageSize'=>5,
            ),
        ));
    }
$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_li',
)); ?>
    </div>
    <div style="clear:both;"></div>
</div>
